package com.tianji.api;

import cn.hutool.core.io.unit.DataUnit;
import com.tianji.api.client.course.CatalogueClient;
import com.tianji.api.client.course.CourseClient;
import com.tianji.api.client.remark.RemarkClient;
import com.tianji.api.client.remark.fallback.RemarkClientFallback;
import com.tianji.api.dto.course.CataSimpleInfoDTO;
import com.tianji.common.utils.DateUtils;
import com.tianji.learning.LearningApplication;
import com.tianji.learning.domain.po.PointsRecord;
import com.tianji.learning.enums.PointsRecordType;
import com.tianji.learning.service.impl.PointsRecordServiceImpl;
import io.lettuce.core.ScriptOutputType;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@SpringBootTest( classes = LearningApplication.class)
public class tset01 {
    @Autowired
    CatalogueClient catalogueClient;
    @Autowired
    PointsRecordServiceImpl pointsRecordService;
@Autowired
    StringRedisTemplate redisTemplate;
    @Test
    public void tset01(){
        // 1.获取上月时间
        LocalDateTime time = LocalDateTime.now().minusMonths(1);
        Set<ZSetOperations.TypedTuple<String>> points_board =
                redisTemplate
                        .opsForZSet()
                        .reverseRangeWithScores("boards:"+ DateUtils.format(time, "yyyyMM"), 0, -1);
        points_board.forEach(System.out::println);
        System.out.println(points_board);

    }
    @Test
    public void tset02(){
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime begin = DateUtils.getDayStartTime(now);
        LocalDateTime end = DateUtils.getDayEndTime(now);
        Integer points = pointsRecordService.lambdaQuery()
                .eq(PointsRecord::getUserId, 2)
                .eq( PointsRecord::getType, PointsRecordType.SIGN)
                .between( PointsRecord::getCreateTime, begin, end)
                .count();
        System.out.println(points);
    }
}
